package com.test;

/**
 * 、写两个线程，一个线程打印 1~52，另一个线程打印字母A-Z。
 * 打印顺序为12A34B56C……5152Z,要求用线程间的通信  (wait noify())
 */
class Th extends Thread{

    int num=1;
    @Override
    public void run() {
        //super.run();
        for (int i = 0; i < 52; i++) {
            demo1 demo1 = new demo1();
            demo1.numberT(num);
            num++;
        }

    }
}
class ThAZ extends Thread{
    int ZiMu = 65;
    @Override
    public void run() {
        for (int i = 0; i < 26; i++) {
            demo1 demo1 = new demo1();
            demo1.az(ZiMu);
            ZiMu++;
        }
    }
}

public class demo1 {
    int index=0;


    public demo1() {

    }

    public synchronized void az(int ziMu){
        while (index%2==0){
            try {
                this.notify();
               // Thread.sleep(100);
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        index++;
        //System.out.println(index);
        //while ()
//        try {
//            //Thread.sleep(100);
//            wait();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println((char) ziMu);



    }

    public synchronized void numberT(int num){
        while (index%2!=0) {

            try {
                this.notify();
                //Thread.sleep(100);
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        index++;
//        System.out.println(index);
        System.out.println(num);
       // num++;
//        try {
//
//            //Thread.sleep(100);
//            wait();
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }



    }

    public static void main(String[] args) {
        Th th = new Th();
        new Thread(th,"数字").start();
        ThAZ thAZ = new ThAZ();
        new Thread(thAZ,"字母").start();
    }




}
